package com.tjcd.project.library_base.base.utils;

import android.app.Activity;
import android.os.SystemClock;

import androidx.annotation.Keep;

import com.blankj.utilcode.util.ToastUtils;
import com.tjcd.project.library_base.common.basicInfor.SugarUrls;

/**
 * @Author jiangKunKun
 * @CreateDate 2021/7/7
 * @Description
 * @SpittingGrooves
 */
@Keep
public class DebugChangeUtil {

    /**
     * 点击次数
     */
    public final static int COUNTS = 5;
    /**
     * 规定有效时间
     */
    public final static long DURATION = 1000;
    /**
     * 次数
     */
    static long[] mHits = new long[COUNTS];

    /**
     * debug模式 切换debug模式
     */
    private static void change() {
        SugarUrls.DEBUG = !SugarUrls.DEBUG; // 环境赋值转变
//        NetManager.resetRetrofit();
        if (SugarUrls.DEBUG) { // 测试
            SugarUrls.baseUrl = SugarUrls.baseDeBugUrl;
        } else { // 正式
            SugarUrls.baseUrl = "正式路径";
        }

    }

    /**
     * 点击几次生效
     *
     * @param count
     * @param time
     */
    public static void continuousClick(int count, long time, Activity activity) {
        //每次点击时，数组向前移动一位
        System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);
        //为数组最后一位赋值
        mHits[mHits.length - 1] = SystemClock.uptimeMillis();
        if (mHits[0] >= (SystemClock.uptimeMillis() - DURATION)) {
            mHits = new long[COUNTS];//重新初始化数组
            ToastUtils.showLong("当前环境为:" + (SugarUrls.DEBUG ? "正式" : "测试"));
            change();
            // todo 回到首页
//            activity.startActivity(new Intent(activity, MainActivity.class)); // 直接欢迎页
            activity.finish();
        }
    }
}
